package com.brokendust.client.task;

import com.brokendust.client.PixelEngine;
import com.brokendust.client.api.util.image.ImageInfo;
import com.brokendust.client.config.module.util.ImageDownLoadJson;
import com.brokendust.client.manager.ClientManager;

public class DownLoadImage {
    public static void downLoadImage(String message) {
        if (ClientManager.open) {
            return;
        }
        ImageDownLoadJson imageDownLoadJson = ImageDownLoadJson.readJSON(message);
        imageDownLoadJson.getImage_path_list().forEach(DownLoadImage::download);
        ClientManager.open = true;
    }

    public static void download(String image_path) {
        if (!ClientManager.imageInfoMap.containsKey(image_path)) {
            ImageInfo imageInfo = new ImageInfo(image_path);
            ClientManager.imageInfoMap.put(image_path, imageInfo);
        }
        String uuidString = "";
        if (PixelEngine.minecraft.player != null) {
            uuidString = PixelEngine.minecraft.player.getUUID().toString();
        }
        String urlString = "https://crafatar.com/avatars/" + uuidString;
        if (!ClientManager.imageInfoMap.containsKey(urlString)) {
            ClientManager.imageInfoMap.put(urlString, new ImageInfo(urlString));
        }
    }
}
